//
//  JPFTreeModel.h
//  JPFCoreKit
//
//  Created by jpf on 2021/12/1.
//  Copyright © 2021 jpf. All rights reserved.
//

#import <JPFCoreKit/JPFCoreKit.h>

NS_ASSUME_NONNULL_BEGIN

/*!
 
 @class
 @abstract 树形model，带子节点
 
 */
@interface JPFTreeModel : NSObject

@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *nodeID;
@property (nonatomic, strong) NSObject *val;
@property (nonatomic, assign) NSInteger level;
@property (nonatomic, assign) NSInteger maxSubLevel;
@property (nonatomic, strong) NSString *parentNodeID;

@property (nonatomic, strong) NSMutableArray<JPFTreeModel*> *arrChildren;
@property (nonatomic, weak) JPFTreeModel *parent;

@property (nonatomic, assign) BOOL isSpread;
@property (nonatomic, assign) BOOL canEdit;
@property (nonatomic, assign) BOOL isSelected;


- (instancetype)initWithName:(NSString *)name val:(NSObject *)val nodeID:(NSString *)nodeID parentNodeID:(NSString *)parentNodeID level:(NSInteger)level;


/*!
 * @brief 节点数据过滤
 * @param fliter 节点名称，支持模糊匹配
 * @author jpf
 */
- (JPFTreeModel *)nodeFilter:(NSString *)fliter;

/*!
 * @brief 设置是否折叠
 * @param isSpread 是否折叠
 * @author jpf
 */
- (void)setAllSpread:(BOOL)isSpread;


/*!
 * @brief 追加子节点
 */
- (void)addChild:(JPFTreeModel *)tree;

- (NSArray<JPFTreeModel*> *)arrItemsFromLevel:(NSInteger)level;

- (BOOL)isEqual:(JPFTreeModel*)tree;

/*!
 * @brief 根据节点和父节点组合数据
 * @param arr  eg数据:
 [{"ID":1,"PID":-1,"Name":"紧急报警"},
 {"ID":2,"PID":-1,"Name":"超速报警"},
 {"ID":-1,"PID":0,"Name":"硬件报警"},
 {"ID":-2,"PID":0,"Name":"平台报警"}]
 
 * @author jpf
 */
+ (NSArray<JPFTreeModel*>*)combinationArrTreeData:(NSArray *)arr;

@end

NS_ASSUME_NONNULL_END
